package org.example.extension.beanPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class CustomInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        // 在Bean实例化之前调用
        if(beanName.equals("beanPostProcessorDemo2")){
            System.out.println("CustomInstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation()");
        }
        return null;
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        // 在Bean实例化之后调用
        if(beanName.equals("beanPostProcessorDemo2")){
            System.out.println("CustomInstantiationAwareBeanPostProcessor.postProcessAfterInstantiation()");
        }
        return true;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // 在Bean初始化之前调用
        if(beanName.equals("beanPostProcessorDemo3")){
            System.out.println("CustomInstantiationAwareBeanPostProcessor.postProcessBeforeInitialization()");
        }
        return bean;
    }
}
